package sample;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import java.util.Random;
public class Food {
    Random random = new Random();
    int x = random.nextInt(Yard.COL*Yard.BLOCK_SIZE)/10*10+10;
    int y = random.nextInt(Yard.ROW*Yard.BLOCK_SIZE)/10*10+10;
    int i = 0;
    public void draw(Canvas canvas) {
        GraphicsContext gc = canvas.getGraphicsContext2D();
        if(i%2==0) {
            gc.setFill(Color.GREEN);
            i++;
        }
        else {
            gc.setFill(Color.RED);
            i++;
        }
        gc.fillOval(x/10*10,y/10*10,Yard.BLOCK_SIZE,Yard.BLOCK_SIZE);
    }
    public  void reAppear(){
        this.x = new Random().nextInt((Yard.COL * Yard.BLOCK_SIZE-10+1)+10) / 10 * 10 ;
        this.y = new Random().nextInt((Yard.ROW * Yard.BLOCK_SIZE-10+1)+10) / 10 * 10 ;
}
}
